package service.impl;

import java.util.List;

import service.ArticleClassService;
import bean.ArticleClass;
import dao.ArticleClassDao;

public class ArticleClassServiceImpl implements ArticleClassService {
	private ArticleClassDao articleClassDao;
	@Override
	public boolean addArticleClass(ArticleClass articleClass) {
		ArticleClass ac=articleClassDao.findArticleClassByTitle(articleClass);
		if(ac==null){
		articleClassDao.addArticleClass(articleClass);
		return true;
		}else{
			return false;
		}
	}

	@Override
	public boolean modifyArticleClass(ArticleClass articleClass) {
		ArticleClass ac=articleClassDao.findArticleClassByTitle(articleClass);
		if(ac==null){
		articleClassDao.modifyArticleClass(articleClass);
		return true;
		}else{
			return false;
		}
	}

	@Override
	public boolean deleteArticleClass(ArticleClass articleClass) {
		ArticleClass ac=articleClassDao.findArticleClassById(articleClass.getId());
		if(ac.getArticlenum()!=0)
			return false;
		else{
			articleClassDao.deleteArticleClass(articleClass);
			return true;
		}
	}

	@Override
	public List getAllArticleClassesByUserid(int id) {
		List l=articleClassDao.findArticleClassesByUserid(id);
		System.out.println(l.size());
		return l;
	}

	public ArticleClassDao getArticleClassDao() {
		return articleClassDao;
	}

	public void setArticleClassDao(ArticleClassDao articleClassDao) {
		this.articleClassDao = articleClassDao;
	}

	@Override
	public ArticleClass getArticleClassById(int id) {
		return articleClassDao.findArticleClassById(id);
	}

}
